package com.zhixi.pattern.important.builderpattern.operation.model;

import java.util.ArrayList;

/**
 * 车模型
 *
 * @作者 ShuHaoNan
 * @邮箱 shuhaonan1@gmail.com
 * @时间 2020/11/15 15:03
 */
public abstract class CarModel {

    private ArrayList<String> sequence = new ArrayList<>();

    /* 开始 */
    protected abstract void start();
    /* 停止 */
    protected abstract void stop();
    /* 喇叭 */
    protected abstract void alarm();
    /* 发动引擎 */
    protected abstract void engineBoom();

    /* 启动 */
    final public void run() {
        sequence.forEach(s -> {
            if (s.equalsIgnoreCase("start")) {
                this.start();
            } else if (s.equalsIgnoreCase("stop")) {
                this.stop();
            } else if (s.equalsIgnoreCase("alarm")) {
                this.alarm();
            } else if (s.equalsIgnoreCase("engineBoom")) {
                this.engineBoom();
            }
        });
    }

    /* 运行顺序 */
    final public void setSequence(ArrayList<String> sequence) {
        this.sequence = sequence;
    }
}
